library(DeclareDesign)
library(rdss)
library(tidyverse)
library(scales)
library(ggdag)
library(ggraph)
library(ggforce)
library(ggtext)

source("code/utilities/make_dag_df.R")
dag <- dagify(Y ~ D + X + U,
              D ~ X,
              X ~ U)

nodes <-
  tibble(
    name = c("U", "X", "D", "Y"),
    label = c("U", "X", "D", "Y"),
    annotation = c(
      "**Unknown heterogeneity**",
      "**Running variable**",
      "**Treatment**<br>X > cutoff",
      "**Outcome variable**"
    ),
    x = c(5, 1, 4, 5),
    y = c(4, 2.5, 2.5, 1), 
    nudge_direction = c("N", "S", "N", "S"),
    data_strategy = "unmanipulated",
    answer_strategy = c("uncontrolled", "controlled", "uncontrolled", "uncontrolled")
  )

ggdd_df <- make_dag_df(dag, nodes)

g <- base_dag_plot %+% ggdd_df

g

ggsave("figures/figure_16.8.pdf", g, width = 6.5, height = 4)
ggsave("figures/figure_16.8.svg", g, width = 6.5, height = 4)
